package com.application.lucky.activity.me;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.application.lucky.R;
import com.application.lucky.config.Config;
import com.application.lucky.manager.UserManagers;
import com.application.lucky.widget.TitlebarView;
import com.application.mylibrary.base.BaseActivity;
import com.application.mylibrary.utils.ToastUtils;

public class HaiBaoActivity extends BaseActivity {

    private TitlebarView mTitleBar;
    private TextView mTvAppName;
    private TextView mTvCode;
    private TextView mTvCopy;
    private ImageView mIvInviteUrlImg;
    private TextView mTvInviteUrl;
    private TextView mTvShare;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private ClipboardManager cm;
    private ClipData mClipData;

    @Override
    public void beforeInit() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_hai_bao;
    }

    private void initView() {
        mTitleBar = (TitlebarView) findViewById(R.id.title_bar);
        mTitleBar.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finishAnim();
            }

            @Override
            public void rightClick() {

            }
        });
        mTvAppName = (TextView) findViewById(R.id.tv_app_name);
        mTvCode = (TextView) findViewById(R.id.tv_code);
        final String userId = UserManagers.getInstance().getUserId();
        setUid(userId);
        mTvCopy = (TextView) findViewById(R.id.tv_copy);
        mTvCopy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// 创建普通字符型ClipData
                mClipData = ClipData.newPlainText("Label", userId+"");
// 将ClipData内容放到系统剪贴板里。
                cm.setPrimaryClip(mClipData);
                ToastUtils.show("复制成功");
            }
        });
        mIvInviteUrlImg = (ImageView) findViewById(R.id.iv_invite_url_img);
        mTvInviteUrl = (TextView) findViewById(R.id.tv_invite_url);
        mTvShare = (TextView) findViewById(R.id.tv_share);
    }

    private void setUid(String uid) {
        try {
            Long integer = Long.valueOf(uid);
            mTvCode.setText("id：" + (integer ^ Config.ID_proguard));
        } catch (Exception e) {
            mTvCode.setText("id：" + uid);
        }


    }
}
